<?php
class LogisticsController extends AppController {

	public $name = 'logistics';
	function beforeFilter() {
	    parent::beforeFilter(); 
		$this->C_auth->autoRedirect = false; //For override login
	    $this->C_auth->allowedActions = array('index','dellog');

	}
	
    //收货地址
	public function dellog() {	
        $address_id=intval(Request::get_args('address_id'));

		$query = array(
				'fields' => array('userlogistics.*'),
				'conditions' => array('userlogistics.user_id' => $this->my->id,'userlogistics.id' => $address_id),
				);	
		$address_rs = POP::exe('[@@:UM userlogistics][@@:QU find:first]',$query);	
		if(empty($address_rs)) {
            $this->flash("该项不存在!", Router::url('logistics/index/'));		
		}else {
		    $this->userlogistics->delete($address_id);
            $this->flash("执行成功！", Router::url('logistics/index/'));		   
		}        		
	}
	
    //收货地址
	public function index() {	
        $address_id=intval(Request::get_args('address_id'));	
        if(!empty($this->data)) {
			$query  = array();	
			$this->data['userlogistics']['user_id'] = $this->my->id;			
			if(!empty($this->data['userlogistics']['id'])) {
			    $address_id = $this->data['userlogistics']['id'];
				$query['keyid'] = $this->data['userlogistics']['id'];				
				$query['set'] = $this->data;					
			}else {			
				$query = $this->data;		
			}
			unset($this->data['userlogistics']['id']);
			POP::exe('[@@:UM userlogistics][@@:QU save]',$query);			
        }
		$query = array(
				'fields' => array('userlogistics.*'),
				'conditions' => array('userlogistics.user_id' => $this->my->id),
				);	
		$address_rs = POP::exe('[@@:UM userlogistics][@@:QU find:all]',$query);	
        $user_info=array(
	        'name'=>'',
	        'user_name'=>'',
	        'telphone'=>'',
	        'carnum'=>'',
	        'money'=>'',
        );
        if($address_id && $address_rs){
	        foreach($address_rs as $value) {
		        if($address_id == $value['userlogistics']['id']) {
			        $user_info = $value['userlogistics'];
		        }
	        }
        }	
        $this->set('user_info',$user_info);		
        $this->set('address_rs',$address_rs);	
        $this->set('address_id',$address_id);
	}
	
}

?>